package edu.nf.bs.service.impl;

import com.github.pagehelper.PageInfo;
import edu.nf.bs.dao.LogisticsMapper;
import edu.nf.bs.entity.Logistics;
import edu.nf.bs.exception.AddException;
import edu.nf.bs.exception.UpdateOrderException;
import edu.nf.bs.service.LogisticsService;

import java.util.List;

public class LogisticsServiceImpl implements LogisticsService {
    private LogisticsMapper logisticsMapper;

    public void setLogisticsMapper(LogisticsMapper logisticsMapper) {
        this.logisticsMapper = logisticsMapper;
    }

    @Override
    public PageInfo<Logistics> queryLogistics(String logistics, Integer pageNum, Integer pageSize) {
        List<Logistics> logisticsList = logisticsMapper.queryLogistics(logistics, pageNum, pageSize);
        PageInfo<Logistics> logisticsPageInfo = new PageInfo<>(logisticsList);
        return logisticsPageInfo;
    }

    @Override
    public void addLogistics(Logistics logistics) {
        Integer integer = logisticsMapper.addLogistics(logistics);
        if(integer!=1){
            throw new AddException("添加物流失败");
        }
    }

    @Override
    public void updateLogisticsStatus(String logisticsId) {
        Integer integer = logisticsMapper.updateLogisticsStatus(logisticsId);
        if(integer!=1){
            throw new UpdateOrderException("修改物流状态失败");
        }
    }
}
